<template>
<div style="text-align: center">

  <el-form ref="form" :model="cus" label-width="150px" style="text-align: center;width: 800px" label-position="left">
    <el-form-item label="顾客身份证号码">
      <el-input v-model.number="cus.cid" ></el-input>
    </el-form-item>

    <el-form ref="form" :model="cus" label-width="150px" style="text-align: left" >
    <el-form-item label="顾客姓名">
      <el-input v-model="cus.name"></el-input>
    </el-form-item>
      <el-form ref="form" :model="cus" label-width="150px" style="text-align: left" >
        <el-form-item label="顾客手机号码">
          <el-input v-model.number="cus.telnum"></el-input>
        </el-form-item>
    <el-form-item label="等级" >
      <el-select v-model.number="cus.grade" placeholder="选择优惠等级">
        <el-option label="普通" value=1></el-option>
        <el-option label="白银" value=2></el-option>
        <el-option label="黄金" value=3></el-option>
        <el-option label="钻石" value=4></el-option>
      </el-select>
    </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="onSubmit">立即创建</el-button>
        <el-button @click="clearAll()">取消</el-button>
      </el-form-item>
  </el-form>
  </el-form>
  </el-form>
  <el-button @click="this.open">点击</el-button>
</div>
</template>
<script>
import instance from "@/untils";
export default {
  data() {
    return {
      cus: {
        name: '',
      }
    }
  },
  methods: {
    onSubmit() {
      console.log(this.cus);
      instance.post("/cus/regCus",this.cus).then(res=>{
            if(res.data.status==200){
             this.open();
            }
           if(res.data.status==500){
            this.$message({
            message:res.data.msg,
            type:"warning"
            });
          }
          }
      )
    },
    clearAll(){
      this.cus={}
    },
    open() {
      this.$confirm('添加成功 是否回到主页面?', '提示', {
        cancelButtonText: '取消',
        confirmButtonText: '确定',
        type: 'success'
      }).then(() => {
        this.$router.push("/")
      }).catch(() => {
       this.clearAll();
      });
    }

  }
}
</script>